package com.kirayous.task3.controller;

import com.kirayous.task3.entity.regionState;
import com.kirayous.task3.service.fetchVirusDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/getData")
@CrossOrigin(origins = "*",maxAge = 3600)
public class fetchVirusDataController {


    @Autowired
    fetchVirusDataService service;


    @GetMapping("/virusData")
    List<regionState> getData(@RequestParam(value = "state", required = false) String state, @RequestParam(value = "country",required = false) String country) throws IOException {


        System.out.println("state:"+state);
        System.out.println("country"+country);

        if (state!=null&&state.trim()=="") state=null;
        if (country!=null&&country.trim()=="")country=null;
        return service.fetchByConditionVirusData(state,country);
    }



}
